home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-06-15 | 2.3 KB | 98 lines | [TEXT/MPS ] |
- (*
- TCPSend connectionID,string -- Send a string to the TCP connection.
- Note: It would be a good idea to add an optional third parameter, which, if present, would cause
- linefeeds to be appended to all carriage returns. This would make it much easier and faster to
- send HyperCard text and CRLF line terminations.
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- pascal -w TCPSend.p
- link -m ENTRYPOINT -o HyperCommands -rt XCMD=7861 -sn Main=TCPSend ∂
- TCPSend.p.o "{Libraries}HyperXLib.o" "{MPW}"Libraries:interface.o
-
- © Copyright 1988 by Apple Computer, Inc.
-
- Initial coding 12/88 by Harry R. Chesley.
- *)
-
- {$R-}
-
- {$S TCPSend } { Segment name must be the same as the command name. }
-
- unit DummyUnit;
-
- interface
-
- uses MemTypes, QuickDraw, OSIntf, HyperXCmd;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- implementation
-
- procedure TCPSend(paramPtr: XCmdPtr); forward;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- begin
- TCPSend(paramPtr);
- end;
-
- procedure TCPSend(paramPtr: XCmdPtr);
-
- type
-
- wdsType = { Write block for TCP driver. }
- record
- size: integer; { Number of bytes. }
- buffer: Ptr; { Pointer to bytes. }
- term: integer; { Zero for end of blocks. }
- end;
-
- var wds: wdsType;
-
- procedure Fail(errMsg: Str255); { set theResult and quit }
- begin
- paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
- exit(TCPSend);
- end;
-
- {$I TCPUtil.inc}
-
- function countString(sPtr: Ptr): longInt;
- { Return the number of characters in the zero-terminated string pointed to by sPtr.
- Note: This should be replaced by a HyperCard callback. }
-
- var count: longInt;
-
- begin
- count := 0;
- while sPtr^ <> 0 do
- begin
- count := count+1;
- sPtr := Ptr(ord4(sPtr)+1);
- end;
- countString := count;
- end;
-
- begin
- if paramPtr^.paramCount <> 2 then Fail('§§§ parameter count is not 2 §§§');
-
- SetUpConnectionID;
-
- { Check for an empty string being sent. }
- if paramPtr^.params[2] = nil then exit(TCPSend);
- if paramPtr^.params[2]^^ = 0 then exit(TCPSend);
-
- { Issue the TCP write. }
- HLock(paramPtr^.params[2]);
- wds.buffer := paramPtr^.params[2]^;
- wds.size := countString(wds.buffer);
- wds.term := 0;
- ZeroIOParms;
- SyncControlBlock.csCode := TCPcsSend;
- PutControlLongAtOffset(ord4(@wds),38);
- if PBControl(@SyncControlBlock,false) <> noErr then Fail('§§§ send failed §§§');
- end;
-
- end.
-